<?php
class Truckaccmodel extends CI_Model{
	function get_dateRange_partnum($date,$partnum,$partname='',$depcode=''){
		$this->db->select('vendorid as vendorcode,
							concat(vfirstname," ",vlastname) as vendername,
							docuno as docuno,
							paydate as docudate,
							concat(larn,LPAD(ticketid,5,0)) as invno,
							paydate as invdate,
							concat(larn,LPAD(ticketid,5,0)) as shipno,
							paydate as shipdate,'
							."'$partnum'".' as partnum,'
							."'$partname'".' as partname,
							larn as inventory,
							larn as location,
							"" as unit,
							net_wght1 as qty,
							cost_unt as price,
							totalcut_price as discount,
							buynet as amount,
							"NOVAT" as vatecode,'
							."'$depcode'".' as depcode,
							buynet1 as cashamount
		',FALSE);
	
		$this->db->from('truck');
		$this->db->join('vendor', 'truck.vendorid = vendor.vendorcode');

		if ($date){
			//$teststring = '2012-01-12 -> 2012-01-13';
			$startdate = substr($date, 0,10);
			$enddate =  substr($date, 14,10);
			if ($enddate == '') $enddate = $startdate;
			$dateRange = "date(extra_paymentdate) BETWEEN '$startdate' AND '$enddate'";
			$this->db->where($dateRange,NULL,FALSE);
		}else{
			//NOW() - INTERVAL 1 DAY
			//$dateRange = 'date(extra_paymentdate) = date(NOW())';
			//$this->db->where($dateRange,NULL,FALSE);
		}
		
		// = "date(extra_paymentdate) BETWEEN '$startdate' AND '$enddate'";
		//$this->db->where($dateRange, NULL, FALSE);  
		$result = $this->db->get();
		return $result;
		//echo $this->db->last_query();
	}
	
function get_dateRange_sum($date){
		
		$this->db->select('posname, 
						sum(net_wght1) as sumqty,
						cost_unt,
						sum(buynet) as sumamount,
						sum(totalcut_price) as sumdiscount,  
						sum(buynet1) as cashamount,
						sum(quantity_prom) as sumpromo,
						sum(buynet1)+sum(quantity_prom) as sumcashpromo,
						
						',FALSE);
	
		$this->db->from('truck');
		$this->db->join('pos_option', 'truck.larn = pos_option.posid');

		if ($date){
			//$teststring = '2012-01-12 -> 2012-01-13';
			$startdate = substr($date, 0,10);
			$enddate =  substr($date, 14,10);
			if ($enddate == '') $enddate = $startdate;
			$dateRange = "date(extra_paymentdate) BETWEEN '$startdate' AND '$enddate'";
			$this->db->where($dateRange,NULL,FALSE);
		}else{
			//NOW() - INTERVAL 1 DAY
			//$dateRange = 'date(extra_paymentdate) = date(NOW())';
			//$this->db->where($dateRange,NULL,FALSE);
		}
		
		//$dateRange = "date(extra_paymentdate) BETWEEN '$startdate' AND '$enddate'";
		//$this->db->where($dateRange, NULL, FALSE);

		$this->db->group_by('larn');
		$this->db->order_by('posid');
		
		$result = $this->db->get();
		//echo $this->db->last_query();
		return $result;
		//echo $this->db->last_query();
	}
	
}